﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Ewk.MachineLearning.Persistance.Interfaces;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Rhino.Mocks;

namespace Ewk.MachineLearning.Persistance.DataAccess.UnitTests
{
    [TestClass]
    public class AddTests : RepositoryTestBase
    {
        [TestMethod]
        public void When_Add_is_called_Then_Catalog_Add_is_called()
        {
            var entity = new TestEntity();

            var catalog = MockRepository.GenerateMock<ICatalog>();

            catalog
                .Expect(c => c.Add(entity))
                .Return(entity)
                .Repeat.Once();
            catalog.Replay();

            var repository = new EntityRepository<TestEntity>(catalog);
            repository.Add(entity);

            catalog.VerifyAllExpectations();
        }

        [TestMethod, ExpectedException(typeof(ArgumentNullException))]
        public void When_Save_is_called_with_null_Then_an_ArgumentNullException_is_thrown()
        {
            var entity = new TestEntity {Id = Guid.NewGuid()};

            var catalog = MockRepository.GenerateMock<ICatalog>();

            catalog
                .Expect(c => c.Add(Arg<TestEntity>.Is.Anything))
                .Return(entity)
                .Repeat.Never();
            catalog.Replay();

            var repository = new EntityRepository<TestEntity>(catalog);
            repository.Add(null);

            catalog.VerifyAllExpectations();
        }
    }
}